﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using VehicleRental.WpfClient.Data;

namespace VehicleRental.WpfClient.ViewModels
{
    public class PublicVehicleRentalVIewModel : ViewModelBase, IPageViewModel
    {
        public string Name
        {
            get
            {
                return "Places public View";
            }
        }

        private ObservableCollection<PlacesViewModel> places;
        private PlacesViewModel currentPlace;

        public ObservableCollection<PlacesViewModel> Places
        {
            get 
            {
                if (this.places == null)
                {
                    var placesEnumerable = DataPersister.GetAll();
                    this.places = new ObservableCollection<PlacesViewModel>();
                    foreach (var place in placesEnumerable)
                    {
                        this.places.Add(place);
                    }
                }

                return this.places;
            }
        }

        public PlacesViewModel CurrentPlace
        {
            get
            {
                if (this.currentPlace == null)
                {
                    var placeCollectionView = CollectionViewSource.GetDefaultView(this.Places);
                    this.currentPlace = placeCollectionView.CurrentItem as PlacesViewModel;
                }

                return this.currentPlace;
            }
        }
    }
}
